package com.ajk.server.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import com.ajk.server.dao.provider.KnowledgeProvider;
import com.ajk.server.model.Knowledge;
import com.ajk.server.model.query.KnowledgeQuery;
import com.ajk.server.model.request.KnowledgeReq;
import com.ajk.server.model.response.KnowledgeRes;

public interface KnowledgeMapper {

	@Select("select * from t_knowledge order by publish_time desc limit #{start},#{limit}")
	public List<KnowledgeRes> list(KnowledgeReq knowledgeReq);
	
	@Select("select * from t_knowledge where id = #{id}")
	public KnowledgeRes detail(Knowledge knowledge);
	
	@Insert("insert into t_knowledge(title,excerpt,pic_url,content,read_count,publish_time) "
			+ " values (#{title},#{excerpt},#{picUrl},#{content},#{readCount},#{publishTime})")
	@Options(useGeneratedKeys=true)
	public Integer add(Knowledge knowledge);
	
	@Delete("delete from t_knowledge where id = #{id}")
	public void delete(Knowledge knowledge);
	
	/**
 	*根据id删除 健康资讯表
 	*/
 	@Delete("delete from t_knowledge where id=#{id}")
 	public Integer deleteById(Integer id);
 	
 	/**
 	* 批量新增 健康资讯表
 	*/
 	@InsertProvider(method="batchInsert",type=KnowledgeProvider.class)
	@Options(useGeneratedKeys=true,keyColumn="id",keyProperty="list[0].id")
 	public Integer batchInsert(List<? extends Knowledge> knowledges);
 	
 	/**
 	* 新增 健康资讯表
 	*/
 	@InsertProvider(method="insert",type=KnowledgeProvider.class)
	@Options(useGeneratedKeys=true)
 	public Integer insert(Knowledge domain);
 
 	
 	/**
 	*更新 健康资讯表
 	*/
 	@UpdateProvider(method="update",type=KnowledgeProvider.class)
 	public Integer update(Knowledge domain);
 	
 	/**
 	*根据ID查询 健康资讯表
 	*/
	@Select("select * from t_knowledge where id=#{id}")
	public KnowledgeRes findById(Integer id);
	
	/**
 	*通过query 查询 健康资讯表
 	*/
 	@SelectProvider(method="findByQuery",type=KnowledgeProvider.class)
 	public List<Knowledge> findByQuery(KnowledgeQuery query);
 	
 	/**
 	*通过query count总条数
 	*/
 	@SelectProvider(method="countByQuery",type=KnowledgeProvider.class)
 	public Integer countByQuery(KnowledgeQuery query);


}
